package logic

import (
	"context"

	"mall/service/backend/common/errorx"
	"mall/service/backend/common/i18n"
	"mall/service/promotion/rpc/internal/svc"
	"mall/service/promotion/rpc/types/promotion"

	"github.com/zeromicro/go-zero/core/logx"
)

type SyncQiniuLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSyncQiniuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SyncQiniuLogic {
	return &SyncQiniuLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// ##25.03.02##
func (l *SyncQiniuLogic) SyncQiniu(in *promotion.SyncQiniuReq) (*promotion.BaseResp, error) {
	if in.Id == 0 || len(in.Url) == 0 {
		return nil, errorx.NewInvalidArgumentError(i18n.ValidationError)
	}

	_, err := l.svcCtx.Activity.SyncQiniu(l.ctx, in.Id, in.MediaId, in.Url)
	if err != nil {
		return nil, err
	}

	return &promotion.BaseResp{}, nil
}
